using System;
using System.Data;
using System.Windows.Forms;

namespace ERP.Classes
{
	/// <summary>
	/// Summary description for csListView.
	/// </summary>
	public class csListView
	{
		public csListView()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public void KetDulieu(ListView myListView,string tableName,string condition,string[] displayFields)
		{
			csCSDL csdl=new csCSDL();
			DataSet myDataset=new DataSet("Dulieu");
			myDataset=csdl.OpenTable(tableName,condition);
			int row;
			myListView.Items.Clear();
			
			try
			{
				row=myDataset.Tables[0].Rows.Count;
				int i=0;
				ListViewItem item=new ListViewItem();
				while (i<row) 
				{
					int j=i+1;
					item=myListView.Items.Add(j.ToString().Trim());
					for (int k=0;k<displayFields.GetLength(0);k++)
					{
						item.SubItems.Add(myDataset.Tables[0].Rows[i][displayFields[k]].ToString().Trim());
						//MessageBox.Show(myDataset.Tables[0].Rows[i][displayFields[k]].ToString());
                    }
					if (i%2 == 0)
					{
						item.ForeColor = System.Drawing.Color.ForestGreen;
						item.BackColor = System.Drawing.Color.Silver;
					}
					else
					{
						item.ForeColor = System.Drawing.Color.Red;
						item.BackColor = System.Drawing.Color.WhiteSmoke;
					}
					i++;
				}
			}
			catch
			{
				
			}
		}
		
		public void KetDulieu(ListView myListView,string sql,string[] displayFields)
		{
			csCSDL csdl=new csCSDL();
			DataSet myDataset=new DataSet("Dulieu");
			myDataset=csdl.SelecSQL(sql);
			int row;
			myListView.Items.Clear();
			
			try
			{
				row=myDataset.Tables[0].Rows.Count;
				int i=0;
				ListViewItem item=new ListViewItem();
				while (i<row) 
				{
					int j=i+1;
					item=myListView.Items.Add(j.ToString().Trim());
					for (int k=0;k<displayFields.GetLength(0);k++)
					{
						item.SubItems.Add(myDataset.Tables[0].Rows[i][displayFields[k]].ToString().Trim());
						//MessageBox.Show(myDataset.Tables[0].Rows[i][displayFields[k]].ToString());
					}
					if (i%2 == 0)
					{
						item.ForeColor = System.Drawing.Color.ForestGreen;
					}
					else
					{
						item.ForeColor = System.Drawing.Color.Red;
					}
					i++;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
	}
}
